﻿<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
</head>
<body>
<table id="tb-fbe" width="90%" style="display:none;margin-left:30px;margin-top:20px;height:170px;font-weight: bold;">
	<tr>
		<td>拜访日期</td>
		<td width="10%">&nbsp;</td>
		<td><input class="easyui-validatebox" readonly value="2012-11-26" type="text" id="feedbackdate" style="width:243px;"></input></td>
	</tr>
	<tr>
		<td>上/下午</td>
		<td>&nbsp;</td>
		<td style="align:right">
			<select id="daytypesel" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:250px;">
				<option selected value="am">上午</option>
				<option value="pm">下午</option>
				<option value="all">全天</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>拜访客户</td>
		<td>&nbsp;</td>
		<td>
			<input id="custree" class="easyui-combotree" value="请选择" data-options="animate:true,onBeforeExpand:function(node){getChildren(node);},required:true" style="width:250px;">
			<div id="div-isinplan" style="font-weight:normal;">计划中&nbsp;&nbsp;<input type="radio" onclick="getUnplanCustomers(2);" name="aa" checked>&nbsp;&nbsp;计划外&nbsp;&nbsp;<input type="radio" onclick="getUnplanCustomers(1);" name="aa"></div>
		</td>
	</tr>
	<tr>
		<td>拜访程序</td>
		<td>&nbsp;</td>
		<td>
			<select id="prosel" class="easyui-combobox" style="width:250px;" data-options="valueField:'id',textField:'text',panelHeight:'auto',required:true">
				<option>请选择</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>上级主管</td>
		<td>&nbsp;</td>
		<td>
			<select id="parentsel" class="easyui-combobox" data-options="valueField:'id',textField:'text',panelHeight:'auto'" style="width:250px;">
				<option>请选择</option>
			</select>
		</td>
	</tr>			
</table>

<style>
.westtable-span1 .westtable-span2 {
	font-family: Courier, "Courier New", monospace;
	font-size: 12px;
}
.westtable-span1 {
	color: #000000;
	font-weight: bold;
}

</style>	

<div id="dlg-fbe" class="easyui-dialog" title="拜访反馈" style="width:750px;height:500px;" data-options="buttons:'#dlg-fbe-btn',resizable:false,closed:true,modal:true,closable:false,cache:false">
	<div class="easyui-layout" id="rightnorthID" style="width:100%;height:100%;padding:0px;">
		<div region="north" style="border:none;height:100px;background:#dbeaf9;overflow:hidden">
			<table border="0" width="717px" style="margin:10px">
				<tr>
					<td width="15%" class="westtable-span1">拜访日期：</td>
					<td width="35%" class="westtable-span2">						
						<input id="visitdatero" disabled type="text" name="customers" value="" style="width:200px;">
					</td>
					<td width="15%" class="westtable-span1">拜访客户：</td>
					<td width="35%" class="westtable-span2">
						<input id="custreero" disabled class="easyui-combotree" name="customers" data-options="required:true" style="width:200px;">
					</td>
				</tr>
				<tr>
					<td class="westtable-span1">开始时间：</td>
					<td class="westtable-span2">
						<input id="visitstarttimero" class="easyui-datetimebox" name="starttime"  data-options="required:false,showSeconds:false"  style="width:200px;"/>  
					</td>
					<td class="westtable-span1">拜访程序：</td>
					<td class="westtable-span2">
						<select disabled id="proselro" class="easyui-combobox" name="visitprocess" style="width:200px;" data-options="valueField:'id',textField:'text',panelHeight:'auto',required:true">
							<option>请选择</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="westtable-span1">结束时间：</td>
					<td class="westtable-span2">
						<input id="visitendtimero" class="easyui-datetimebox" name="endtime" data-options="required:false,showSeconds:false" style="width:200px;"/>  
					</td>
					<td class="westtable-span1">协访人：</td>
					<td class="westtable-span2">
						<select id="parentselro" disabled class="easyui-combobox" name="parentemployee" data-options="valueField:'id',textField:'text',panelHeight:'auto'" style="width:200px;">
							<option>无</option>
						</select>
					</td>
				</tr>
			</table>		
		</div>
		<div region="center" style="padding:0px;border:none;overflow:auto">
			<div id="tab-main" class="easyui-tabs" data-options="tools:'#tab-tools'" style="height:330px;"></div>			
			<div id="tab-tools">
				<a href="#" id="tab-tools-add" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="javascript:showProdSelect();"></a>
				<a href="#" id="tab-tools-remove" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="javascript:removeCheckedItems();"></a>
				<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-refresh'" onclick="javascript:showTabContent();"></a>
			</div>
		</div>
	</div>
</div>  
<div id="dlg-fbe-btn" style="background:#dbeaf9;">
	<a href="#" id="saveVisitBaseBtn" class="easyui-linkbutton" onclick="javascript:saveItemDetail();">&nbsp;&nbsp;保存&nbsp;&nbsp;</a>
	<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dlg-fbe').dialog('destroy');$('#tab-main').dialog('destroy')">&nbsp;&nbsp;关闭&nbsp;&nbsp;</a>
</div>
<div id="dlg-prd-sel" class="easyui-dialog" style="background:#dbeaf9;width:450px;height:140px;"
	data-options="buttons:'#dlg-prd-btn',resizable:false,closed:true,modal:true">
</div>
<div id="dlg-prd-btn" style="background:#dbeaf9;">
	<a href="#" class="easyui-linkbutton" onclick="javascript:addSelectItems();">&nbsp;&nbsp;添加&nbsp;&nbsp;</a>
	<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dlg-prd-sel').dialog('close')">&nbsp;&nbsp;关闭&nbsp;&nbsp;</a>
</div>
<div id="dlg-ide" class="easyui-dialog" style="width:550px;height:450px;"
	data-options="buttons:'#dlg-ide-btn',resizable:false,closed:true,modal:true">
</div>
<div id="dlg-ide-btn" style="background:#dbeaf9;">
	<a href="#" class="easyui-linkbutton" onclick="javascript:saveItemDetail();">&nbsp;&nbsp;保存&nbsp;&nbsp;</a>
	<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dlg-ide').dialog('close')">&nbsp;&nbsp;关闭&nbsp;&nbsp;</a>
</div>
<script>
	/**
		动态添加拜访客户节点

	*/
	oval_node_str = '';
	function getChildren(node){
		oval_node = node;
		var oval_node_ids = oval_node.id.split('f');
		if(oval_node_str.indexOf(oval_node.id)!=-1)return;
		var paramsstr = "{'gradeflag':'"+oval_node_ids[1]+"','employeeid':"+oval_user_search+",'customerid':'"+oval_node_ids[0]+"'}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getvisitcustomers',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getChildrenCallback);
	}
	
	function getChildrenCallback(data){
		if(data.successflag=="true"){	
			if(data.result.customers != undefined){
				var t = $('#custree').combotree('tree');
				t.tree('append', {
					parent: oval_node.target,
					data: data.result.customers
				});
				oval_node_str += oval_node.id;
				t.tree('collapse',oval_node.target);
				t.tree('expand',oval_node.target);				
			}
		}	
	}
	
	/**
		保存项目反馈明细
	*/
	function saveItemDetail(){
		var str = "[";
		for(i=0;i<itemDetails.length;i++){
			var type = itemDetails[i].feedbacktype;
			var id = eval('itemDetails[i].visit'+itemtype+'feedbackid');
			var dictype = itemDetails[i].sourcetype;
			var value;
			str += "{'visit"+itemtype+"feedbackid':"+ id +",";
			switch(type){
				case 1:
					value = $('#'+itemtype+id).val();
					if(value=="")value="null";
					str += "'feedbacknumber':'"+ value +"'}";
					break;
				case 2:
					value = $('#'+itemtype+id).val();
					str += "'feedbacktext':'"+ value +"'}";
					break;
				case 3:
					if($('#'+itemtype+id).attr("checked")=="checked")
						value = 'N';
					else
						value = 'Y';
					str += "'feedbackcheck':'"+ value +"'}";
					break;
				case 4:
					value = $('#'+itemtype+id).combobox('getValue');
					if(value=="")value="null";
					str += "'feedbackselect':'"+ value +"'}";
					break;
				case 5:
					value = $('#'+itemtype+id).val();
					if(value=="")value = "null";
					str += "'feedbackattrachid':'null'}";
					break;
				case 6:
					value = "";
					var multiObj = $("[name='"+itemtype+id+"']").each(function(){
						if(this.checked){
							value += this.value +',';
						}
					}); 
					if(value!=""){
						value = value.substring(0,value.length-1);
					}
					str += "'feedbackmultiselect':'"+ value +"'}";
					break;
				case 8:
					value = $('#'+itemtype+id).combobox('getValue');
					if(value=="")value="null";
					str += "'feedbackselect':'"+ value +"'}";
					break;
			}
			if(i!=itemDetails.length-1)str += ",";
		}
		str += "]";
        var starttime = $('#visitstarttimero').datetimebox('getValue');	
		var endtime = $('#visitendtimero').datetimebox('getValue');		
		var paramsstr = "{'starttime':'"+starttime+"','endtime':'"+endtime+"','visitfeedbackid':'"+visitfeedbackid+"','itemtype':'"+itemtype;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += "','"+ itemtype +"itemdetail':"+ str;
		}
		paramsstr += "}"
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'savefeedbackdetails',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, saveItemDetailCallback);		
	}
	
	function saveItemDetailCallback(data){
		if(data.successflag=="true"){		
			$.messager.show({
				title:'提示',
				msg:'数据保存成功！',
				timeout:3000,
				showType:'slide'
			});
		}
	}
	
	/**
		获取基本信息tab内容
	*/
	function getFeedbackInfo(){	
		var paramsstr = "{'employeeid':"+oval_user_search;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += ",'itemtype':'"+itemtype
			paramsstr += "','visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}"
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getfeedbackdetails',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getFeedbackInfoCallback);
	}
	
	function getFeedbackInfoCallback(data){
		if(data.successflag=="true"){	
			var strHTML = '';
			feedbackinfo = data.result.feedbackinfo;
			if(feedbackinfo!=undefined){
				//var orgname=feedbackinfo.orgname;
				//var address=feedbackinfo.address;
				//var telephone=feedbackinfo.telephone;
				//var feedbackdate=feedbackinfo.feedbackdate;
				//var feedbackqty=feedbackinfo.feedbackqty;
				//var description=feedbackinfo.description;
				strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
				strHTML += '<p class="westtable-span1">客户地址</p>';		
				strHTML += '<p style="padding-left:10px;">无</p>';						
				strHTML += '</div>';
				strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
				strHTML += '<p class="westtable-span1">联系方式</p>';		
				strHTML += '<p style="padding-left:10px;">无</p>';						
				strHTML += '</div>';
				strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
				strHTML += '<p class="westtable-span1">上次拜访日期</p>';		
				strHTML += '<p style="padding-left:10px;">无</p>';						
				strHTML += '</div>';
				strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
				strHTML += '<p class="westtable-span1">本月拜访次数</p>';		
				strHTML += '<p style="padding-left:10px;">无</p>';						
				strHTML += '</div>';
				strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
				strHTML += '<p class="westtable-span1">上次拜访未解决事项</p>';		
				strHTML += '<p style="padding-left:10px;">无</p>';						
				strHTML += '</div>';
			}	
			showItemDetailDialog(strHTML)
		}
	}
	
	/**
		根据所选项目获取反馈明细

	*/
	function getItemDetail(itemid,_title){
		itemDlgTitle = _title;	
		var paramsstr = "{'employeeid':"+oval_user_search;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			if(itemid!=undefined)paramsstr += ",'itemid':"+itemid;
			paramsstr += ",'itemtype':'"+itemtype
			paramsstr += "','visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}"
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getfeedbackdetails',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getItemDetailCallback);
	}
	
	function getItemDetailCallback(data){
		if(data.successflag=="true"){	
			var strHTML = '';
			itemDetails = data.result.itemdetails;
			if(itemDetails != undefined){
				for(i=0;i<itemDetails.length;i++){
					var type = itemDetails[i].feedbacktype;
					var id = eval("itemDetails[i].visit"+itemtype+"feedbackid");
					var dictype = itemDetails[i].sourcetype;
					var actionid,value;
					switch(type){
						case 1:
							value = itemDetails[i].feedbacknumber;
							break;
						case 2:
							value = itemDetails[i].feedbacktext;
							break;
						case 3:
							value = itemDetails[i].feedbackcheck;
							break;
						case 4:
							value = itemDetails[i].feedbackselect;
							actionid = itemDetails[i].visitprocessactionid
							break;
						case 5:
							value = itemDetails[i].feedbackattrachid;
							break;
						case 6:
							value = itemDetails[i].feedbackmultiselect;
							break;
						case 8:
							value = itemDetails[i].feedbackselect;
							actionid = itemDetails[i].relatedactionid
							break;
					}
					strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
					strHTML += '<p class="westtable-span1">'+itemDetails[i].actionname+'</p>';		
					strHTML += '<p style="padding-left:10px;">'+createFormEle(type,id,value,actionid,dictype)+'</p>';						
					strHTML += '</div>';			
				}
			}		
			showItemDetailDialog(strHTML);
		}
	}
	/**
		行动指南中级联列表的关联设定
	*/
	function chg4RelatedType(dictype,actionid,dicvalue){
		for(j=0;j<itemDetails.length;j++){
			if(itemDetails[j].relatedactionid==actionid){
				var vid = eval("itemDetails[j].visit"+itemtype+"feedbackid");
			}
		}
		for(k=0;k<dictionary.length;k++){
			if(dictionary[k].type==dictype){
				if(dictionary[k].value==dicvalue){
					dictype = dictionary[k].relatedtype;
					break;
				}
			}
		}	
		var newdic = [{"valuename":"请选择","value":"null","selected":true}];
		for (p=0;p<dictionary.length;p++){
			if(dictionary[p].type==dictype){
				newdic = newdic.concat(dictionary[p]);
			}
		}	
		$('#'+itemtype+vid).combobox({   
			url:'combobox_data.json',   
			valueField:'value',   
			textField:'valuename'  
		}); 
		$('#'+itemtype+vid).combobox('loadData',newdic);	
	}
	/**
		创建行动指南的表单元素

	*/
	function createFormEle(type,id,value,actionid,dictype){
		var elementStr;
		if(value==undefined)value="";
		if(type==1){						
			elementStr = '<input style="width:390px;" class="easyui-numberbox" onchange="editFlag=1" id="'+ itemtype + id +'" value="'+ value +'"/>';	
			return elementStr;
		}else if(type==2){							
			elementStr = '<textarea style="width:390px;height:50px" onchange="editFlag=1" id="'+ itemtype + id +'">'+ value +'</textarea>';
			return elementStr;						
		}else if(type==3){
			var flag = '';
			if(value=='Y')flag = 'checked';
			elementStr = '<input id="'+ id +'" '+ flag +' onchange="editFlag=1" type="checkbox"/><label style="padding-right:10px;">是/否</label>';	
			return elementStr;	
		}else if(type==4){
			elementStr = '<select style="width:400px;" data-options="onSelect: function(rec){editFlag=1;chg4RelatedType(\''+ dictype +'\','+ actionid +',rec.value)},panelHeight:\'auto\'" class="easyui-combobox" id="'+ itemtype + id +'"><option value="null">请选择</option>';
			for (p=0;p<dictionary.length;p++){
				if(dictionary[p].type==dictype){
					var flag = "";
					if(dictionary[p].value==value){
						flag = "selected";
					}
					elementStr += '<option '+ flag +' value="'+ dictionary[p].value +'">'+ dictionary[p].valuename +'</option>';
				}
			}						
			elementStr += '</select>';
			return elementStr;	
		}else if(type==5){
			elementStr = '上传';	
			return elementStr;	
		}else if(type==6){
			elementStr = '';	
			valueArray = value.split(",");
			for (p=0;p<dictionary.length;p++){
				if(dictionary[p].type==dictype){
					for (q=0;q<valueArray.length;q++){
						if(dictionary[p].value == valueArray[q])break;
					}
					var flag = "";
					if(q < valueArray.length){
						flag = "checked";
					}
					elementStr += '<input name="'+ itemtype + id +'" '+ flag +' onchange="editflag=1" type="checkbox" value="'+ dictionary[p].value +'"/><label style="padding-right:10px;">'+ dictionary[p].valuename +'</label>';	
				}
			}							
			return elementStr;	
		}else if(type==8){
			elementStr = '<select style="width:400px;" data-options="panelHeight:\'auto\'" class="easyui-combobox" id="'+ itemtype + id +'" " onchange="editFlag=1;"><option value="null">请选择</option>';
			var dicvalue;
			if(value!=''){
				for(j=0;j<itemDetails.length;j++){
					if(itemDetails[j].visitprocessactionid==actionid){
						dicvalue = itemDetails[j].feedbackselect;
						dictype = itemDetails[j].sourcetype;
					}
				}
				for(k=0;k<dictionary.length;k++){
					if(dictionary[k].type==dictype){
						if(dictionary[k].value==dicvalue){
							dictype = dictionary[k].relatedtype;
							break;
						}
					}
				}				
				for (p=0;p<dictionary.length;p++){
					if(dictionary[p].type==dictype){
						var flag = "";
						if(dictionary[p].value==value){
							flag = "selected";
						}
						elementStr += '<option '+ flag +' value="'+ dictionary[p].value +'">'+ dictionary[p].valuename +'</option>';
					}
				}	
			}				
			elementStr += '</select>';
			return elementStr;	
		}
	}	
	
	/**
		显示反馈明细
	*/
	function showItemDetailDialog(str){
		if(itemtype!='base' && itemtype!='info'){
			$('#dlg-ide').dialog({   
				title: currentTab+"—"+itemDlgTitle, 
				content: str
			}); 
			$('#dlg-ide').dialog('open');
		}else{			
			var _tab = $('#tab-main').tabs('getTab',currentTab); 
				$('#tab-main').tabs('update',{
					tab: _tab,	
					options: {
						content: str
				}
			});
		}
	}
	
	/**
		移除所选反馈项目

	*/
	function removeCheckedItems(){
		var checkedItemArray = $('#tb-grid-'+itemtype).datagrid('getChecked');	
		if(checkedItemArray.length==0)return;
		$.messager.confirm('警告','是否删除?', function(r){
			if (r){
				execRemoveItems(checkedItemArray);
			}
		});	
	}
	function execRemoveItems(arr){
		var checkedids =  new Array();
		for(i=0;i<arr.length;i++){
			checkedids[i] = eval("arr["+i+"]."+fieldValue);
		}	
		var paramsstr = "{'employeeid':"+oval_user_search;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += ",'itemids':'"+checkedids.join()+"','itemtype':'"+itemtype+"','visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'deletefeedbackitems',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, removeItemsSuccessCallback);
	}
	function removeItemsSuccessCallback(data){
		if(data.successflag=="true"){				
			$.messager.show({
				title:'提示',
				msg: '数据清除完毕！',
				timeout:3000,
				showType:'slide'
			});
			showTabContent();
		}
	}
	/**
		显示项目添加列表
	*/
	function showProdSelect() {
		setDialog();
		$('#dlg-prd-sel').dialog('open');
		$('#dlg-prd-sel').dialog('refresh', 'FeedBackProdSelect.html');
	}
	
	/**
		根据标识显示反馈内容
	*/
	function showTabContent(){
		switch(currentTab){
			case '基本信息':
				itemtype = "info";
				break;
			case '基本反馈':
				itemtype = "base";
				break;
			case '品类反馈':
				itemtype = "cate";
				fieldCode = "categorycode";
				fieldText = "categoryname";
				fieldValue = "categoryid";
				break;
			case '品牌反馈':
				itemtype = "brand";
				fieldCode = "brandcode";
				fieldText = "brandname";
				fieldValue = "brandid";
				break;
			case '产品反馈':
				itemtype = "sku";
				fieldCode = "prodcode";
				fieldText = "prodname";
				fieldValue = "prodid";
				break;
			case '竞品反馈':
				itemtype = "cpt";
				fieldCode = "prodcptcode";
				fieldText = "prodcptname";
				fieldValue = "prodcptid";
				break;
		}
		if(currentTab=='基本信息'){
			getFeedbackInfo();
			return;
		}else if(currentTab!='基本反馈'){
			var _tab = $('#tab-main').tabs('getTab',currentTab); 
				$('#tab-main').tabs('update',{
					tab: _tab,	
					options: {
						content: '<table id="tb-grid-'+itemtype+'"></table>'
				}
			});
			$('#tb-grid-'+itemtype).datagrid({
				height:299,
				nowrap: false,
				autoRowHeight: false,
				striped: true,
				singleSelect:false,
				fitColumns:true,
				checkOnSelect: false,
				selectOnCheck: false,
				columns:[[
					{field: fieldValue,checkbox: true},
					{field: fieldCode,title:currentTab.substr(0,2)+"代码",width:208},
					{field: fieldText,title:currentTab.substr(0,2)+"名称",width:402},
					{field: 'orgid',title:'操作',width:80,align:'center',
						formatter:function(value,row,index){	
							var str = '<a href="#" id="editFeedbackBtn" class="easyui-linkbutton" data-options="iconCls:"icon-edit"" onclick="javascript:getItemDetail('+eval('row.'+fieldValue)+',\''+eval('row.'+fieldText)+'\');">编辑</a>';
							return str;
						}
					}
				]]
			});
			getItemDatas();
		}else{
			getItemDetail();
		}
	}
	
	/**
		获取反馈项目列表数据
	*/
	function getItemDatas(){
		var paramsstr = "{'employeeid':"+oval_user_search;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += ",'flag':1,'itemtype':'"+itemtype+"','visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getfeedbackitems',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getItemDatasCallback);
	}
	
	function getItemDatasCallback(data){
		if(data.successflag=="true"){	
			if(data.result.allitems != undefined){
				$('#tb-grid-'+itemtype).datagrid('loadData',{                                                                     
					"rows":data.result.allitems                                                          
				});	
			}
		}
	}
	
	/**
		设置添加项目列表标题
	*/
	function setDialog(){
		$('#dlg-prd-sel').dialog({   
			title: "相关"+currentTab.substr(0,2)
		}); 	
	}
	
	$(function(){
		/**
			获取反馈初始数据
		*/
		getSelectDatas();
	});
	
	function getSelectDatas(){
		var paramsstr = "{'cudate':'"+ovaldateStr+"','employeeid':"+oval_user_search;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += ",'visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getvisitfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getSelectCallback);
	}
	
	function getSelectCallback(data){
		if(data.successflag=="true"){
			if(data.result.enabled=="false"){
				$('#daytypesel').combobox('disable');
				$('#prosel').combobox('disable');
				$('#parentsel').combobox('disable');	
				$('#custree').combotree('disable');	
				$('#div-isinplan').hide();
				$('#saveFeedbackBtn').linkbutton('disable');
				$('#tb-fbe').show();
			}else{
				$('#daytypesel').combobox('enable');
				$('#prosel').combobox('enable');
				$('#parentsel').combobox('enable');	
				$('#custree').combotree('enable');	
				$('#div-isinplan').show();
				$('#saveFeedbackBtn').linkbutton('enable');
				$('#tb-fbe').show();			
			}
			$('#feedbackdate').val(ovaldateStr);
			$('#prosel').combobox('loadData',data.result.processsel);		
			$('#parentsel').combobox('loadData',data.result.parentempsel);	
			$('#parentsel').combobox('setValue',data.result.parentempsel[0].id);
			$('#ydCustree').combotree('loadData',data.result.customers);		
			$('#custree').combotree('loadData',data.result.customers);
			$('#proselro').combobox('loadData',data.result.processsel);		
			$('#parentselro').combobox('loadData',data.result.parentempsel);	
			$('#custreero').combotree('loadData',data.result.customers);
			var feedbackinfo_info = data.result.feedbackinfo;
			
			if(feedbackinfo_info.starttime != null && feedbackinfo_info.starttime != undefined){
			var date_str = formatCalendarDate(new Date(data.result.feedbackinfo.starttime.time),'-');
			var time_str = formatCalendarTime(new Date(data.result.feedbackinfo.starttime.time),'h','m','n');
				$('#visitstarttimero').datetimebox('setValue', date_str +" " + time_str)
					
			}else{
			     var time_str = getHMStime('h','m','n');
				$('#visitstarttimero').datetimebox('setValue', time_str)
			}
			if(feedbackinfo_info.endtime != null && feedbackinfo_info.endtime != undefined){
			var date_str = formatCalendarDate(new Date(data.result.feedbackinfo.endtime.time),'-');
			var time_str = formatCalendarTime(new Date(data.result.feedbackinfo.endtime.time),'h','m','n');
			     $('#visitendtimero').datetimebox('setValue', date_str +" " + time_str);
			}else{
			     var time_str = getHMStime('h','m','n');
				$('#visitendtimero').datetimebox('setValue', time_str);
			}
			if(data.result.feedbackinfo != undefined){				
				$('#visitdatero').val(ovaldateStr);
				$('#daytypesel').combobox('setValue',data.result.feedbackinfo.daytype);
				$('#prosel').combobox('setValue',data.result.feedbackinfo.processid);
				$('#proselro').combobox('setValue',data.result.feedbackinfo.processid);
				//$('#parentsel').combobox('setValue',data.result.parentempsel);
				if(data.result.targetinfo != undefined){
					$('#custree').combotree('setValue',data.result.targetinfo.text);
					$('#custreero').combotree('setValue',data.result.targetinfo.text);
				}else{
					$('#custree').combotree('setValue',data.result.feedbackinfo.targetid+'f113f1');
					$('#custreero').combotree('setValue',data.result.feedbackinfo.targetid+'f113f1');
				}
			}
			if(data.result.dictionary != undefined)dictionary = data.result.dictionary;
			if(data.result.typeinfo != undefined){
				$('#tab-main').tabs({   
					onSelect: function(title,index){  
						currentTab = title; 			
						$('#tab-tools-add').linkbutton('enable');
						$('#tab-tools-remove').linkbutton('enable');			
						$('#saveVisitBaseBtn').hide();	
						if(title=="基本反馈" || title=="基本信息"){
							$('#tab-tools-add').linkbutton('disable');
							$('#tab-tools-remove').linkbutton('disable');
						}
						if(title=="基本反馈")$('#saveVisitBaseBtn').show();
						showTabContent();		
					}   
				});  
				
				addTab("info","基本信息",true);
				
				if(data.result.typeinfo.base>0){
					addTab("base","基本反馈",false);
				}
				if(data.result.typeinfo.cate>0){
					addTab("cate","品类反馈",false);
				}
				if(data.result.typeinfo.brand>0){
					addTab("brand","品牌反馈",false);
				}
				if(data.result.typeinfo.sku>0){
					addTab("sku","产品反馈",false);
				}
				if(data.result.typeinfo.cpt>0){
					addTab("cpt","竞品反馈",false);
				}
			}
		}
	}
	
	/**
		计划内、计划外拜访客户的切换

	*/
	function getUnplanCustomers(num){
		var paramsstr = "{'cudate':'"+ovaldateStr+"','isplan':"+num+",'employeeid':"+oval_user_search+",'visitfeedbackid':"+visitfeedbackid+"}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getvisitfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getUnplanCustomersCallback);
	}
	
	function getUnplanCustomersCallback(data){
		if(data.successflag=="true"){
			if(data.result.customers == undefined)
				$('#custree').combotree('setValue','请选择');	
			else{	
				$('#custree').combotree('setValue','请选择');
				$('#custree').combotree('loadData',data.result.customers);	
			}
		}
	}
	
	/**
		保存feedback反馈
	*/
	function saveFeedback(){
		var customer = $('#custree').combotree('getValue');
		var processid = $('#prosel').combobox('getValue');
		oval_msg = '数据保存成功！';
		var parentemployeeid = $('#parentsel').combobox('getValue');
		var daytype = $('#daytypesel').combobox('getValue');
		var targetid = null;
		var targettype = null;
		var orgid = null;
		if(customer=="请选择"){
			$.messager.alert('提示','请选择一个拜访客户！','info');
			return;
		}else{
			if(customer.split('f').length!=1){
				var targetid = customer.split('f')[0];
				var targettype = customer.split('f')[1];
				var orgid = customer.split('f')[2];
				if(targettype=='113' || targettype=='114'){
					targettype='1';
					orgid = customer.split('f')[0];
				}
			}
		}
		if(processid=="请选择"){
			$.messager.alert('提示','请选择一个拜访程序！','info');
			return;
		}
		var paramsstr = "{'orgid':'"+orgid+"','cudate':'"+ovaldateStr+"','operate':'save','employeeid':"+oval_user_search+",'targetid':"+targetid+",'targettype':"+targettype+",'processid':'"+processid+"','parentemployeeid':'"+parentemployeeid+"','daytype':'"+daytype+"','visitfeedbackid':"+visitfeedbackid+"}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'savevisitfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, saveFeedbackSuccess);
	}
	
	/**
		删除feedback反馈
	*/
	function deleteFeedback(){
		$.messager.confirm('警告','是否删除?', function(r){
			if (r){
				execDeleteFeedback();
			}
		});	
	}
	
	function execDeleteFeedback(){
		oval_msg = '数据已经删除！';
		var paramsstr = "{'operate':'delete','employeeid':"+oval_user_search+",'visitfeedbackid':"+visitfeedbackid+"}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'savevisitfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, saveFeedbackSuccess);
	}
	
	function saveFeedbackSuccess(data){
		if(data.successflag=="true"){
			$('#dlg-fbm').dialog('close');			
			$.messager.show({
				title:'提示',
				msg: oval_msg,
				timeout:3000,
				showType:'slide'
			});
			refresh();
		}
	}	

	/**
		显示反馈面板
	*/
	function showFeedbackEdit() {
		$('#dlg-fbm').dialog('close');
		$('#dlg-fbe').dialog('open');
	}
	
	/**
		根据反馈内容添加tab面板
	*/
	function addTab(_id,_title,_selected){
		if($('#tab-main').tabs('getTab',_title)==null){
			$('#tab-main').tabs('add',{
				id: _id,
				title: _title,
				selected: _selected
			});	
		}
	}

</script>
<body>
<html>